package com.wwg.warehouse.utils

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type

inline fun <reified T> genericType(): Type = object : TypeToken<T>() {}.type

inline fun <reified T> Gson.fromJsonObject(json: String?): T? {//可转成任意类型
    return kotlin.runCatching {
        fromJson(json, genericType<T>()) as? T
    }.onFailure {
        it.printStackTrace()
    }.getOrNull()
}